#include<unistd.h>
#include<iostream>
#include<pthread.h>
#include<vector>

#define MAX 3

class My_Pthread
{
public:
    My_Pthread(pthread_t id,int name)
    :_id(id),_name(name)
    {}

    //线程ID
    pthread_t _id=0;
    //线程名
    int _name;
};

//线程任务函数
void* handle(void* arg)
{
    //防止线程跑太快
    sleep(1);
    //强转
    My_Pthread* ptr=(My_Pthread*)arg;


    return NULL;
}

int main()
{
    //用指针来存取线程信息
    std::vector<My_Pthread*> pthread_pointer;

    for(int i=1;i<=MAX;i++)
    {
         pthread_t id;
        //线程执行任务
        My_Pthread* ptr=new My_Pthread(id,i);
        //存储线程数据
        pthread_pointer.push_back(ptr);

        pthread_create(&id,NULL,handle,(void*)ptr);
        ptr->_id=id;
    }

    //线程等待
    for(int i=0;i<MAX;i++)
    {
        void* ptr;
        pthread_join(pthread_pointer[i]->_id,&ptr);
        std::cout<<*((int*)ptr)<<std::endl;
    }
    //回收空间
    for(int i=0;i<MAX;i++)
    {
        delete pthread_pointer[i];
    }

    return 0;
}